package com.xiangmu.controler;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xiangmu.mappers.JuanMapper;
import com.xiangmu.mappers.UserMapper;
import com.xiangmu.pojo.Juan;
import com.xiangmu.pojo.User;
import com.xiangmu.util.JsonResult;

@RestController
public class JuanControler extends BaseController
{

	@Autowired
	private JuanMapper juanMapper;
	
	@Autowired
	private UserMapper UserMapper;
	
	@RequestMapping("/juanAdd")
	public JsonResult<Void> juanAdd(@RequestBody Juan juan) 
	{
		juanMapper.insert(juan);
        return new JsonResult<>(66);
		
    }
	
	
	@RequestMapping("/juanMine")
	public JsonResult<List> juanMine(HttpSession session) 
	{
		User user=(User)session.getAttribute("user");
		
		List<Juan> juanList=juanMapper.findByUser(user.getUid());
		for(Juan juan : juanList)
		{
			juan.setUser(UserMapper.findByUid(juan.getUser_id()));
		}
		
		return new JsonResult<>(66,juanList);
		
    }
	
	@RequestMapping("/juanDel")
	public JsonResult<Void> juanDel(int id) 
	{
		juanMapper.delete(id);
		return new JsonResult<>(66);
    }
	
	
	@RequestMapping("/juanMana")
	public JsonResult<List> juanMana() 
	{
		List<Juan> juanList=juanMapper.select("");
		for(Juan juan : juanList)
		{
			juan.setUser(UserMapper.findByUid(juan.getUser_id()));
		}
		return new JsonResult<>(66,juanList);
		
    }
	
	
	
	@RequestMapping("/juanUpdate")
	public JsonResult<Void> update(@RequestBody Juan juan) 
	{
		juanMapper.update(juan);
		return new JsonResult<>(66);
    }
	
	
	@RequestMapping("/juanRes")
	public JsonResult<List> juanRes(String shijian) 
	{
		List<Juan> juanList=juanMapper.select(shijian.trim());
		for(Juan juan : juanList)
		{
			juan.setUser(UserMapper.findByUid(juan.getUser_id()));
		}
		return new JsonResult<>(66,juanList);
		
    }
	
	
}
